/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.help.service;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.modules.help.dao.SystemHelpOptionTypeDao;
import com.chlitina.store.modules.help.entity.SystemHelpOptionType;
import com.google.common.collect.Maps;

/**
 * 系统帮助类型Service
 * @author lvbo
 * @version 2014-03-31
 */
@Component
@Transactional(readOnly = true)
public class SystemHelpOptionTypeService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(SystemHelpOptionTypeService.class);
	
	@Autowired
	private SystemHelpOptionTypeDao systemHelpOptionTypeDao;
	
	public SystemHelpOptionType get(Long id) {
		return systemHelpOptionTypeDao.findOne(id);
	}
	
	public Page<SystemHelpOptionType> find(Page<SystemHelpOptionType> page, SystemHelpOptionType systemHelpOptionType) {
		DetachedCriteria dc = systemHelpOptionTypeDao.createDetachedCriteria();
		dc.addOrder(Order.desc("id"));
		return systemHelpOptionTypeDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public Map<Long, String> findAll() {
		Map<Long, String> typeMap = Maps.newHashMap();
		Iterable<SystemHelpOptionType> findAll = systemHelpOptionTypeDao.findAll();
		Iterator<SystemHelpOptionType> it = findAll.iterator();
		while (it.hasNext()) {
			SystemHelpOptionType type = it.next();
			typeMap.put(type.getId(), type.getName());
		}
		return typeMap;
	}
	
	@Transactional(readOnly = false)
	public void save(SystemHelpOptionType systemHelpOptionType) {
		systemHelpOptionTypeDao.save(systemHelpOptionType);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		systemHelpOptionTypeDao.delete(id);
	}
	
}
